/*
    Copyright (c) 2009 Pavol Malosek a.k.a. malo

    This file is part of ComComLib.

    ComComLib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    ComComLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __DEVICE_INFO_HPP_INCLUDED__
#define __DEVICE_INFO_HPP_INCLUDED__

#include <iostream>
#include <stdint.h>

namespace lcc
{
    //  General constants
    enum {
        //  maximum numbed of measuring channels for device.
        max_channels = 4
    };

    //  Constansts to use for ADC to real value calculations.
    struct calc_constants_t { 
        float k_n_arg;
        float q_n_arg;
        float k_n_usr;
        float q_n_usr;
    };

    enum input_type_t {
        in_temp_ni,                    //  t Ni1000/6180
        in_temp_pt,                    //  t Pt1000/3850
        in_hum, 
        in_u_i,
        in_bin,                        //  binary
        in_count_16,                   //  counter 16b
        in_count_32,                   //  counter 32b
        in_off                         //  switched OFF - no measurement
    };

    struct value_t {
        input_type_t input_type;
        uint16_t adc_value;
        float value;
    };

    struct record_t {
        uint64_t stamp;
        value_t values [max_channels];
    };

    struct device_info_t {
        //  logging period in seconds
        unsigned int per;
        
        //  true for cyclic logging mode
        //  false for noncyclic logging mode
        bool lincyk;
        
        //  Active channels mask 0th bit for first channel
        unsigned char  act_channels;
        
        //  Number of active channles, one-s in act_channels
        unsigned int act_channels_count; 

        //  Type of the logger
        //  1 for Rxxxx, 2 for Sxxxx
        int type;

        //  Model of the logger
        int model;

        //  logger switched ON
        bool dev_on;

        //  dealayed start (date, time)
        bool dly_on;
        
        //  logging start by magnet enabled
        bool mag_on;

        //  logging end by magnet enabled
        bool mag_off;
    
        //  logging only outside of alar.limits
        bool mimo_al; 

        //  linaerisation of AD converter is switched ON
        bool adc_lin;

        //  Input type
        input_type_t input_type [max_channels];

        //  Constants for calculations.
        calc_constants_t calc_constants [max_channels];   
        
        //  size of data memory installed.
        size_t data_memory_size;

        //  data memory is more than 90% full
        bool EE_90;

        //  data memory full
        bool EE_full;

        //  recording in progress
        bool rec_run;

        //  record pointer
        uint16_t record_ptr;
    };
 
    struct device_codes_t {
        int type;
        int model;
        std::string name;
        std::string measured_values;
        unsigned char channel_mask;
        unsigned char konfig_mask;
        bool konfig_and;               //  Config byte AND with config_mask for tru
                                       //  OR for false
    };
}
#endif

